package com.vctgo.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.system.domain.TTemplate;
import com.vctgo.system.service.ITTemplateService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 模块Controller
 *
 * @author vctgo
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/template")
public class TTemplateController extends BaseController
{
    @Autowired
    private ITTemplateService tTemplateService;

    /**
     * 查询模块列表
     */
    @RequiresPermissions("system:template:list")
    @GetMapping("/list")
    public AjaxResult list(TTemplate tTemplate)
    {
        IPage<TTemplate> list = tTemplateService.selectTTemplatePage(tTemplate);
        return AjaxResult.success(list);
    }

    /**
     * 导出模块列表
     */
    @RequiresPermissions("system:template:export")
    @Log(title = "模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTemplate tTemplate)
    {
        List<TTemplate> list = tTemplateService.selectTTemplateList(tTemplate);
        ExcelUtil<TTemplate> util = new ExcelUtil<TTemplate>(TTemplate.class);
        util.exportExcel(response, list, "模块数据");
    }

    /**
     * 获取模块详细信息
     */
    @RequiresPermissions("system:template:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        TTemplate tTemplate = tTemplateService.selectById(id);
        System.out.println(tTemplate);
        return success(tTemplate);
    }

    /**
     * 新增模块
     */
    @RequiresPermissions("system:template:add")
    @Log(title = "模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTemplate tTemplate)
    {
        return toAjax(tTemplateService.insertTTemplate(tTemplate));
    }

    /**
     * 修改模块
     */
    @RequiresPermissions("system:template:edit")
    @Log(title = "模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTemplate tTemplate)
    {
        return toAjax(tTemplateService.updateTTemplate(tTemplate));
    }

    /**
     * 删除模块
     */
    @RequiresPermissions("system:template:remove")
    @Log(title = "模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTemplateService.deleteTTemplateByIds(ids));
    }
}
